# -*- coding: utf-8 -*-
"""
Created on Sat Sep 17 10:34:02 2022

@author: 123
"""


#分别对聚类0 1 2 计算均值和方差


new_df_risk1_kmeans_0=new_df_risk1_kmeans.query('kmeans==0')
# 8568
new_df_risk1_kmeans_1=new_df_risk1_kmeans.query('kmeans==1')
#8616
new_df_risk1_kmeans_2=new_df_risk1_kmeans.query('kmeans==2')
#10960                                           

# kmeans	原始记录	最终需要数据	高斯增加需要记录
# 0	8568	60120	51552	103104
# 1	8616	60457	51841	103682
# 2	10960	76904	65944	131888
new_df_risk1_kmeans_2.mean()
new_df_risk1_kmeans_1.mean()
new_df_risk1_kmeans_0.mean()

#使用高斯模拟生成数据 

 from  sklearn.datasets import make_gaussian_quantiles
 import numpy as np
 import pandas as pd


new_df_risk1_kmeans_2_mean=[1,0.061239,-0.004126,-1.130953,-0.975049,-0.027053,0.916606,0.029015,0.970985,0.273175,0.018704,0.145073,0,0.762682,0.34188,0.531843,0.126277,1]
new_df_risk1_kmeans_1_mean=[1,-0.969336,-0.233423,0.510758,0.449077,0.045877,0.905409,0.039926,0.960074,0.257312,0.015552,0.152159,0,0.772516,0.367108,0.487117,0.145775,1]
new_df_risk1_kmeans_0_mean=[1,0.863438,0.032547,0.5472,0.644086,-0.095278,0.923086,0.025677,0.974323,0.249066,0.024043,0.152194,0,0.771942,0.330299,0.540966,0.128735,1]


make_gaussian_kmeans2=make_gaussian_quantiles(n_samples=131888,n_features=18, n_classes=1,mean=new_df_risk1_kmeans_2_mean)
make_gaussian_kmeans1=make_gaussian_quantiles(n_samples=103682,n_features=18, n_classes=1,mean=new_df_risk1_kmeans_1_mean)
make_gaussian_kmeans0=make_gaussian_quantiles(n_samples=103104,n_features=18, n_classes=1,mean=new_df_risk1_kmeans_0_mean)



make_gaussian_kmeans_column=['Risk_Flag','Income','Age','Experience','CURRENT_JOB_YRS','CURRENT_HOUSE_YRS','Married/Single_single','House_Ownership_owned','House_Ownership_rented','Car_Ownership_yes','Profession_is_handle_affairs_personnel','Profession_is_person_in_charge_of_enterprises_and_institutions','Profession_is_production_transport_worker','Profession_is_professiona_skill_personnel','STATE_high','STATE_low','STATE_middle', 'is_outlier']



make_gaussian_kmeans2_df=pd.DataFrame(make_gaussian_kmeans2[0])
make_gaussian_kmeans1_df=pd.DataFrame(make_gaussian_kmeans1[0])
make_gaussian_kmeans0_df=pd.DataFrame(make_gaussian_kmeans0[0])


make_gaussian_kmeans2_df.columns=make_gaussian_kmeans_column
make_gaussian_kmeans1_df.columns=make_gaussian_kmeans_column
make_gaussian_kmeans0_df.columns=make_gaussian_kmeans_column


make_gaussian_kmeans2_df['Risk_Flag']=1
make_gaussian_kmeans1_df['Risk_Flag']=1
make_gaussian_kmeans0_df['Risk_Flag']=1

make_gaussian_kmeans2_df['is_outlier']=1
make_gaussian_kmeans1_df['is_outlier']=1
make_gaussian_kmeans0_df['is_outlier']=1




#聚类数据检验 
#data_scaled = pd.DataFrame(data_scaled, columns=new_df_risk1.columns).to_numpy()


y_pre_kmeans_2=model_kmeans.predict(make_gaussian_kmeans2_df.to_numpy())   #预测聚类模型

y_pre_kmeans_1=model_kmeans.predict(make_gaussian_kmeans1_df.to_numpy())   #预测聚类模型

y_pre_kmeans_0=model_kmeans.predict(make_gaussian_kmeans0_df.to_numpy())   #预测聚类模型



#列重命名
#y_pre_kmeans_df=pd.DataFrame(y_pre_kmeans)
y_pre_kmeans_2_df=pd.DataFrame(y_pre_kmeans_2)
y_pre_kmeans_1_df=pd.DataFrame(y_pre_kmeans_1)
y_pre_kmeans_0_df=pd.DataFrame(y_pre_kmeans_0)


p_col=['kmeans']
#y_pre_kmeans_df.columns=p_col

y_pre_kmeans_2_df.columns=p_col
y_pre_kmeans_1_df.columns=p_col
y_pre_kmeans_0_df.columns=p_col

#new_df_risk1_kmeans=pd.concat([new_df_risk1_reset, y_pre_kmeans_df], join="inner", axis=1)


new_make_gaussian_kmeans2_df=pd.concat([make_gaussian_kmeans2_df, y_pre_kmeans_2_df], join="inner", axis=1)
new_make_gaussian_kmeans1_df=pd.concat([make_gaussian_kmeans1_df, y_pre_kmeans_1_df], join="inner", axis=1)
new_make_gaussian_kmeans0_df=pd.concat([make_gaussian_kmeans0_df, y_pre_kmeans_0_df], join="inner", axis=1)

#剔除预测分类值 不是的当前分类的值的数据 
new_make_gaussian_kmeans2_df=new_make_gaussian_kmeans2_df.query('kmeans==2')
new_make_gaussian_kmeans1_df=new_make_gaussian_kmeans1_df.query('kmeans==1')
new_make_gaussian_kmeans0_df=new_make_gaussian_kmeans0_df.query('kmeans==0')

#111542
#77361
#77482

